package com.hitechbangla.fctu.form;

import com.hitechbangla.fctu.base.GameScene;
import com.hitechbangla.fctu.base.PressedButtonEnum;
import com.sun.speech.freetts.Voice;
import fctu.simulator.HTB_MAIN;
import java.awt.Window.Type;


/**
 *
 * @author deb kanti
 */
public class AircraftTools extends javax.swing.JInternalFrame
{
    private HTB_MAIN htb_main;
    private Voice voice;
    private boolean commandButtonPressed;
    
    public AircraftTools(HTB_MAIN htb_main) 
    {
        super("Aircraft Tools", true, true, true, true);
        initComponents();
        this.htb_main = htb_main;    
        jButtonDebug.setVisible(false);
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonCommand = new javax.swing.JButton();
        jButtonLaunch = new javax.swing.JButton();
        jButtonECM = new javax.swing.JButton();
        jButtonDashboard = new javax.swing.JButton();
        jButtonDebug = new javax.swing.JButton();
        jButton2ChangeCallSign = new javax.swing.JButton();

        setTitle("Aircraft Tools");
        setPreferredSize(new java.awt.Dimension(250, 200));
        getContentPane().setLayout(null);

        jButtonCommand.setText("Command");
        jButtonCommand.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCommandActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonCommand);
        jButtonCommand.setBounds(10, 10, 130, 30);

        jButtonLaunch.setText("Launch");
        jButtonLaunch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLaunchActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonLaunch);
        jButtonLaunch.setBounds(10, 40, 130, 30);

        jButtonECM.setText("ECM");
        jButtonECM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonECMActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonECM);
        jButtonECM.setBounds(10, 100, 130, 30);

        jButtonDashboard.setText("Dashboard");
        jButtonDashboard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDashboardActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonDashboard);
        jButtonDashboard.setBounds(10, 70, 130, 30);

        jButtonDebug.setText("Debug");
        jButtonDebug.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDebugActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonDebug);
        jButtonDebug.setBounds(10, 160, 130, 30);

        jButton2ChangeCallSign.setText("Change CallSign");
        jButton2ChangeCallSign.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ChangeCallSignActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2ChangeCallSign);
        jButton2ChangeCallSign.setBounds(10, 130, 130, 30);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonCommandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCommandActionPerformed
        //CommandAircraft commandAircraft = new CommandAircraft(htb_main.gameScene);
	//commandButtonPressed = true;
	//executeCommandWithVoiceResponse(htb_main.gameScene);
	//new commandExecutingThread(htb_main.gameScene, commandButtonPressed).start();
        //commandAircraft.setVisible(true);
	CommandAircraftNew commandAircraftNew = new CommandAircraftNew(htb_main.gameScene);
	commandAircraftNew.setVisible(true);
    }//GEN-LAST:event_jButtonCommandActionPerformed

    private void jButtonLaunchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLaunchActionPerformed
        // TODO add your handling code here:
	LaunchAircraft launchAc = new LaunchAircraft(htb_main.gameScene);
	commandButtonPressed = false;
	launchAc.setVisible(true);
    }//GEN-LAST:event_jButtonLaunchActionPerformed

    private void jButtonDebugActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDebugActionPerformed
        // TODO add your handling code here:
	//System.out.println("From AircraftTools aircraft type size" + htb_main.gameScene.getAirCraftTypeStringArray().length);
	//System.out.println("base list size "+ htb_main.gameScene.getBaseListStringArray().length);
	////System.out.println("" + htb_main.gameScene.get);
    }//GEN-LAST:event_jButtonDebugActionPerformed

    private void jButtonDashboardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDashboardActionPerformed
        AircraftDashboard aircraftDashboard = new AircraftDashboard();
	aircraftDashboard.setVisible(true);
    }//GEN-LAST:event_jButtonDashboardActionPerformed

    private void jButton2ChangeCallSignActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ChangeCallSignActionPerformed
        // TODO add your handling code here:
        ChangeCallSign cs= new ChangeCallSign();
        cs.setVisible(true);
    }//GEN-LAST:event_jButton2ChangeCallSignActionPerformed
    private void jButtonECMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonECMActionPerformed
        // TODO add your handling code here:
	
	//AddECM addECM = new AddECM();
	//addECM.setVisible(true);
	htb_main.lastPressedButton = PressedButtonEnum.ECM;
    }//GEN-LAST:event_jButtonECMActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AircraftTools.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AircraftTools.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AircraftTools.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AircraftTools.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AircraftTools(null).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2ChangeCallSign;
    private javax.swing.JButton jButtonCommand;
    private javax.swing.JButton jButtonDashboard;
    private javax.swing.JButton jButtonDebug;
    private javax.swing.JButton jButtonECM;
    private javax.swing.JButton jButtonLaunch;
    // End of variables declaration//GEN-END:variables

    
    private void executeCommandWithVoiceResponse(GameScene gameScene) 
    {
	
//        while(commandButtonPressed)  
//        {  
//	    voice.speak("Enter commmand");
//	    
//	    String command = null;
//	    try {
//		command = br.readLine();
//	    } catch (IOException ex) {
//		Logger.getLogger(AircraftTools.class.getName()).log(Level.SEVERE, null, ex);
//	    }
//	    if(AircraftUtility.compareWithCommandRegEx(command))
//	    {
//		String callSignCommand = command.substring(0, 3); 
////		    jTextAreaCommandLog.setText(callSignCommand +"\n");
////		    //System.out.println(callSignCommand);
//		boolean flagAircraftFound=false;
//		for(Aircraft aircraft: gameScene.airCraftList)
//		{
//		    if(aircraft.getAircraftState().getCallSign().equals(callSignCommand))
//		    {
//			aircraft.executeCommand(command);  
//			voice.speak("Executing command "+ command);
//			flagAircraftFound = true;
//			break;
//		    }
//		}
//
//		if(flagAircraftFound==false)
//		{
//		    voice.speak("Aircraft not found, aircraft not found");
//		}
//	    }
//	    else
//	    {
//		voice.speak("Disregard, Wrong command, Disregard, wrong command");
//	    }
	    
//        }  
        
    }

    private void setType(Type type) {
        //throw new UnsupportedOperationException("Not yet implemented");
    }
    
}
